653A - Bear and Three Balls - CodeForces Solution


brute force implementation sortings *900

Please click on ads to support us..

Python Code:

n=int(input().split(" ")[0])
dls=input().split(" ")
bls=list()
for i in range(0,n):
    bls.append(int(dls[i]))
for i in bls:
    for j in bls:
        for k in bls:
            y=sorted([i,j,k])
            if y[1]-y[0]==y[2]-y[1]==1:
                print("YES")
                exit(0)
print("NO")

C++ Code:

#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
int t[51],fr[1001];
int main()
{
    int n,ok;
    cin>>n;
    for(int i=1; i<=n; ++i){
        cin>>t[i];
        fr[t[i]]++;}
    ok=0;
    for(int i=1; i<=1000; ++i){
        if((fr[i] != 0) && (fr[i+1] != 0) && (fr[i+2] != 0))
            ok=1;}
    if(ok == 1)
        cout<<"YES";
       else
        cout<<"NO";
    return 0;
}


Comments

Submit
0 Comments
More Questions

1005B - Delete from the Left
94A - Restoring Password
1529B - Sifid and Strange Subsequences
1455C - Ping-pong
1644C - Increase Subarray Sums
1433A - Boring Apartments
1428B - Belted Rooms
519B - A and B and Compilation Errors
1152B - Neko Performs Cat Furrier Transform
1411A - In-game Chat
119A - Epic Game
703A - Mishka and Game
1504C - Balance the Bits
988A - Diverse Team
1312B - Bogosort
1616B - Mirror in the String
1660C - Get an Even String
489B - BerSU Ball
977C - Less or Equal
1505C - Fibonacci Words
1660A - Vasya and Coins
1660E - Matrix and Shifts
1293B - JOE is on TV
1584A - Mathematical Addition
1660B - Vlad and Candies
1472C - Long Jumps
1293D - Aroma's Search
918A - Eleven
1237A - Balanced Rating Changes
1616A - Integer Diversity